﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
//using EntityDA;

/// <summary>
/// Summary description for QLKhachHang
/// </summary>
public class QLKH
{
    public QLKH()
    { }
    public List<KhachHang> getAllKh()
    {
        List<KhachHang> list = new List<KhachHang>();
        ConnectionDB con = new ConnectionDB();
        string sql = "select * from khachhang"; ;      
        con.Cmd.CommandText = sql;
        SqlDataReader reader = con.Cmd.ExecuteReader();
        KhachHang kh = null;
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                kh = new KhachHang();
                kh.Makh = reader.GetString(0);
                kh.Hoten = reader.GetString(2);
                kh.Diachi = reader.GetString(3);
                kh.Sodt = reader.GetDecimal(4);
                list.Add(kh);
            }
        }
        return list;
    }

    public void DangkyKH(KhachHang kh)
    {
        try
        {
            ConnectionDB cn = new ConnectionDB();           
            cn.Cmd.Parameters.Add(new SqlParameter("@ma", kh.Makh));
            cn.Cmd.Parameters.Add(new SqlParameter("@matkhau", kh.Matkhau));
            cn.Cmd.Parameters.Add(new SqlParameter("@hoten", kh.Hoten));
            cn.Cmd.Parameters.Add(new SqlParameter("@diachi", kh.Diachi));
            cn.Cmd.Parameters.Add(new SqlParameter("@sodt", kh.Sodt));
            cn.Cmd.CommandType = CommandType.StoredProcedure;
            cn.Cmd.CommandText = "DangKykh";
            cn.Cmd.ExecuteNonQuery();
        }
        catch
        {
            //return false; 
        }
        //return true;
    }
}